
#ifndef key_word_tree_h
#define key_word_tree_h

#include <stdio.h>
#include <vector>
#include <string>

struct KeyWordArea
{
public:
    KeyWordArea(int _start = 0,int _end = 0):start(_start),length(_end){}
    int start;
    int length;
};

std::vector<std::string> SplitWord(std::string words);
std::string ComposeStringVector(std::vector<std::string> vec);
void ReplaceFilterWord(std::vector<std::string> &source,std::vector<KeyWordArea> areas);


class KeyWordTreeNode
{
public:
    KeyWordTreeNode(const std::string &key,KeyWordTreeNode *parent);
    ~KeyWordTreeNode();
    const static std::string endKey;
private:
    const std::string key_;
    std::vector<KeyWordTreeNode *> children_;
    KeyWordTreeNode *parent_;
public:
    const std::string GetKey();
    int CompareKey(const std::string &key);
    void AddChilrenWithSentence(const std::string &sentence);
    KeyWordTreeNode* AddChild(const std::string &key);
    void AddChildren(const std::vector<std::string> &keys,size_t index);
    KeyWordTreeNode *GetChildWithKey(const std::string &key);
    KeyWordTreeNode *GetNext();
    KeyWordTreeNode *GetNext(KeyWordTreeNode *node);
};


/*
    //example for init
    KeyWordTree keyWordTree;
    keyWordTree.GetRootNode()->AddChilrendWithSentence(keyWords);
*/

/*
    //example for filter
    
    std::string keyNeedFilter = "testkey";
    std::vector<std::string> strVec = SplitWord(keyNeedFilter);
    std::vector<KeyWordArea > areas = keyWordTree.GetKeyWordAreas(strVec);
    ReplaceFilterWord(strVec,areas);
    std::string filterRes = ComposeStringVector(strVec);
*/
class KeyWordTree{
public:
    const static std::string rootKey;
    KeyWordTree();
    ~KeyWordTree();
    KeyWordArea GetKeyWordArea(const std::vector<std::string> strVec,size_t start);
    std::vector<KeyWordArea> GetKeyWordAreas(const std::vector<std::string> strVec);
    KeyWordTreeNode *GetRootNode();
private:
    KeyWordTreeNode *root_;
};


#endif /* key_word_tree_h */
